
export function getnewMenus(menus, checkedKeys) {
    // console.log(menus);
    let result = getResult(menus)
    function getResult(menuss) {
        let arr = []
        menuss?.forEach(item => {
            if (item.children) {
                // console.log(item.key);
                if (checkedKeys.includes(item.key)) {
                    arr.push({ ...item })
                } else {
                    const childlist = []
                    if (checkedKeys.join(',').match(item.key)) {
                        arr.push({ ...item })
                    }
                    item.children.forEach((item,index) => {
                        if (checkedKeys.includes(item.key)) {
                            childlist.push(item)
                        }
                    })
                    if (childlist.length !== 0) {
                        arr[arr.length - 1].children = childlist
                    }
                }
            } else {
                if (checkedKeys.includes(item.key) ) {
                    arr.push({ ...item })
                }
            }
        })
        return arr
    }
    return result
}

// 判断当前请求的地址是不是在路由系统中
export function isContainMenus (menus, pathname) { // ++++++++++
    let bool = menus.some(item => {
      if (item.children) {
        if (item.key === pathname) {
          return true
        } else {
          return item.children.some(it => it.key === pathname)
        }
      } else {
        return item.key === pathname
      }
    })
    
    return bool
  }